package com.mateng.treasurechest.view.weather.activity

import android.os.Bundle
import android.util.Log
import com.bumptech.glide.Glide
import com.mateng.treasurechest.R
import com.mateng.treasurechest.base.BaseActivity
import com.mateng.treasurechest.model.weather.bean.EveryDayImgBean
import com.mateng.treasurechest.presenter.weather.WeatherPresenter
import com.mateng.treasurechest.view.weather.callback.IWeatherResultCallBack
import kotlinx.android.synthetic.main.activity_weather.*

class WeatherActivity : BaseActivity<WeatherPresenter>(), IWeatherResultCallBack {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_weather)

//        IWeatherService.instance.getEveryDayImg()

        val weatherPresenter = WeatherPresenter()

        weatherPresenter.http_getEveryDayImg(this)


    }

    // 请求成功
    override fun onEveryDayImg(t: EveryDayImgBean?) {
//        t?.images?.get(0)?.url
        Log.d("WeatherActivity", t?.images?.get(0)?.url)

        t?.images?.get(0)?.url?.let {

            t.images?.get(0)?.url = "http://s.cn.bing.net" + t.images?.get(0)?.url

            t.images?.get(0)?.url = t.images?.get(0)?.url?.replace("1920x1080", "1080x1920")
        }

        // 加载图片
        Glide.with(iv_background)
                .load(t?.images?.get(0)?.url ?: R.mipmap.ic_launcher)
                .into(iv_background)
    }

}
